// pages/add_ device/add_ device.js
let app = getApp();  
Page({  
  data: {  
    isSubmit: false,  
    warn: "",  
    applianceId: "",  
    device_name: "",  
    groupName:"",
    type: "灯"  
  },  

  
  formSubmit: function (e) {//设备绑定  
    console.log('form发生了submit事件，携带数据为：', e.detail.value);  
    let { applianceId, device_name, groupName, type } = e.detail.value;  
    if (!applianceId || !groupName) {  
      this.setData({  
        warn: "序列号或安装位置为空！",  
        isSubmit: true  
      })  
      return;  
    }else{
      wx.request({ //post到weixin_devicesupervise.php
        url: app.globalData.devicesupervise_url,
        data: {
          openid: wx.getStorageSync('openid'),
          applianceId: applianceId,  
          device_name: device_name,  
          groupName:groupName,
          code:"adddevice"
        },
        header: {
          'Content-Type': 'application/x-www-form-urlencoded'
        },
        method: 'POST',
        success: function (res) {
          console.log(res)
          console.log(res.data.length)
        },
      })
    this.setData({  
      warn: "",  
      isSubmit: true,  
      applianceId, 
      device_name, 
      groupName, 
      type  
    })  
  }  
  },   
})